package com.cls.business.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.MaxIndex;
import com.cls.business.mapper.MaxIndexMapper;
import com.cls.business.service.IMaxIndexService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;

/**
 *  Service实现
 *
 * @author wandering
 * @date 2020-11-24 18:22:37
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class MaxIndexServiceImpl extends ServiceImpl<MaxIndexMapper, MaxIndex> implements IMaxIndexService {

    @Override
    public PageInfo<MaxIndex> findMaxIndexs(QueryRequest request, MaxIndex maxIndex) {
        LambdaQueryWrapper<MaxIndex> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<MaxIndex> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<MaxIndex> findMaxIndex(MaxIndex maxIndex) {
	    LambdaQueryWrapper<MaxIndex> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
        if(maxIndex.getPlanId() != null){
            queryWrapper.eq(MaxIndex::getPlanId, maxIndex.getPlanId());
        }
        if(maxIndex.getTopicId() != null){
            queryWrapper.eq(MaxIndex::getTopicId, maxIndex.getTopicId());
        }
        if(maxIndex.getType() != null){
            queryWrapper.eq(MaxIndex::getType, maxIndex.getType());
        }
        if(maxIndex.getYear() != null){
            queryWrapper.eq(MaxIndex::getYear, maxIndex.getYear());
        }
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createMaxIndex(MaxIndex maxIndex) {
        this.save(maxIndex);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMaxIndex(MaxIndex maxIndex) {
        this.saveOrUpdate(maxIndex);
    }

}
